﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Controls
{
    public partial class ListContentSanGiaoDich : System.Web.UI.UserControl
    {
        public static int catid;
        public static int idloai;
        public static int cur;
        public static int sizepage = 18;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["currentPage"] != null)
            {
                cur = Convert.ToInt32(Request.QueryString["currentPage"].ToString());
            }
            else
            {
                cur=1;
            }
            if (Request.QueryString["content"] != null)
            {

                if (Request.QueryString["IDLoai"] != null)
                {
                    idloai = Convert.ToInt32(Request.QueryString["IDLoai"].ToString());
                    if (idloai != 1)
                    {
                        idloai = Convert.ToInt32(Request.QueryString["IDLoai"].ToString());
                        rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.Paging9Param("pagingsearch9Param", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "desc", "SanGiaoDich_TieuDe", Request.QueryString["content"].ToString(), "LoaiTinRao_ID", idloai.ToString(), true);
                        rpt_sangiaodich.DataBind();

                      
                    }
                    else
                    {

                        rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.Paging7Param("pagingsearch7Param", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "desc", "SanGiaoDich_TieuDe", Request.QueryString["content"].ToString(), true);
                        rpt_sangiaodich.DataBind();
                    }
                }
                else
                {

                    rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.Paging7Param("pagingsearch7Param", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "desc", "SanGiaoDich_TieuDe", Request.QueryString["content"].ToString(), true);
                    rpt_sangiaodich.DataBind();
                }
            }
            else if (Request.QueryString["ID"] != null && Request.QueryString["ID"] !="" )
            {
                if (Request.QueryString["IDLoai"] != null)
                {
                    idloai = Convert.ToInt32(Request.QueryString["IDLoai"].ToString());
                    if (idloai != 1)
                    {
                        idloai = Convert.ToInt32(Request.QueryString["IDLoai"].ToString());
                        rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.Paging9Param("paging9Param", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "desc", "Category_ID1", catid.ToString(), "LoaiTinRao_ID", idloai.ToString(), true);
                        rpt_sangiaodich.DataBind();
                    }
                    else
                    {
                        catid = Convert.ToInt32(Request.QueryString["ID"].ToString());
                        rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.Paging7Param("paging7Param", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "desc", "Category_ID1", catid.ToString(), true);
                        rpt_sangiaodich.DataBind();
                    }
                }
                else
                {
                    catid = Convert.ToInt32(Request.QueryString["ID"].ToString());
                    rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.Paging7Param("paging7Param", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "desc", "Category_ID1", catid.ToString(), true);
                    rpt_sangiaodich.DataBind();
                }
            }
            else
            {
                if (Request.QueryString["IDLoai"] != null)
                {
                    idloai = Convert.ToInt32(Request.QueryString["IDLoai"].ToString());
                      string[] listurl = Request.Url.AbsoluteUri.Split('/');
                    string url = listurl[listurl.Length - 1];
                    string tab = "";
                    if (listurl.Length > 2)
                        tab = listurl[listurl.Length - 2];

                    if (tab == "search")
                    {
                        // Tim kiem nang cao
                        if (idloai == 1)
                        {
                            rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.PagingAdvanceSearch("paging_search_advance", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "DESC", TimKiemNangCao.condition, true);


                            rpt_sangiaodich.DataBind();
                        }
                        else
                        {
                            TimKiemNangCao.catCondition = " AND LoaiTinRao_ID = " + idloai;
                            rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.PagingAdvanceSearch("paging_search_advance", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "DESC", TimKiemNangCao.condition+TimKiemNangCao.catCondition, true);


                            rpt_sangiaodich.DataBind();
                        }
                    }
                    else
                    {
                        if (idloai == 1)
                        {
                            rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.Paging5Param("paging5Param", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "desc", true);
                            rpt_sangiaodich.DataBind();
                        }
                        else
                        {
                            rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.Paging7Param("paging7Param", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "desc", "LoaiTinRao_ID", idloai.ToString(), true);
                            rpt_sangiaodich.DataBind();
                        }
                    }
                }
                else
                {
                    string[] listurl = Request.Url.AbsoluteUri.Split('/');
                    string url = listurl[listurl.Length - 1];
                    string tab = "";
                    if (listurl.Length > 2)
                        tab = listurl[listurl.Length - 2];

                    if (tab == "search")
                    {

                        rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.PagingAdvanceSearch("paging_search_advance", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(),sizepage.ToString(), "DESC", TimKiemNangCao.condition + TimKiemNangCao.catCondition, true);


                        rpt_sangiaodich.DataBind();
                    }
                    else
                    {
                        rpt_sangiaodich.DataSource = DAL.DCollector.DBCollector.Instance.Paging5Param("paging5Param", "tbl_SanGiaoDich", "SanGiaoDich_Date", cur.ToString(), sizepage.ToString(), "desc", true);
                        rpt_sangiaodich.DataBind();
                    }
                }
            }
        }


    
    }
}